<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <div ref="myDom">我是一个元素</div>
    <span ref="span">我是一个span</span>
    <!-- 特殊情况 -->
    <ul>
      <li ref="li" v-for="i in 2">{{i}}</li>
    </ul>
    <button @click="fn">获取dom</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      methods: {
        fn () {
          // this.$refs 是收集了视图中所有加了ref属性的dom元素
          // this.$refs = {myDom: 'dom元素',span: 'dom元素',li: ['li对象','li对象']}
          const dom = this.$refs.myDom
          console.log(this.$refs)
          console.log(dom)
        }
      }
    })
  </script>
</body>
</html>